define( [
		'module',
		'underscore',
		'jquery',
		'backbone',
		'marionette',
//		'model/list', 
		'view/grid', 
		'view/addBookView',
		'view/simpleList',
		'view/footnote'
	],
function( module, _, $, Backbone, Marionette, GridView, AddBookView, ComplexView, FootnoteView ) {
	console.log("Loading module " + module.id + " from " + module.uri + "...");
	var AppController = Marionette.Controller.extend({
		initialize: function() {
			console.log("Controller: initialized");
			this.listenTo( appCTX, 'form:processed', this.processFormData );
		},

		processFormData: function(str) {
			debugger;
			var fData = JSON.parse(str);
			console.log("Controller: processFormData method");
			window.App.collection.create(fData);
		},

		displayBooks : function (){
			console.log("Controller: displayBook method");
		},

		showFileMenu: function() {
			console.log("Controller: destroyLibrary called");
			$('#tab01').removeClass('applicationMenuItemActive');
			$('#tab02').removeClass('applicationMenuItemActive');
			$('#tab03').removeClass('applicationMenuItemActive');
			$('#tab04').removeClass('applicationMenuItemActive');
			$('#tab05').addClass('applicationMenuItemActive');
			window.App.table.empty();
		},

		destroyLibrary: function() {
			debugger;
			console.log("Controller: destroyLibrary called");
			$('#tab01').addClass('applicationMenuItemActive');
			$('#tab02').removeClass('applicationMenuItemActive');
			$('#tab03').removeClass('applicationMenuItemActive');
			$('#tab04').removeClass('applicationMenuItemActive');
			$('#tab05').removeClass('applicationMenuItemActive');
			window.App.table.empty();
		},

		showAddBook: function() {
			console.log("Controller: addBook called");
//			var list = new SampleCollection();
			$('#tab01').removeClass('applicationMenuItemActive');
			$('#tab02').addClass('applicationMenuItemActive');
			$('#tab03').removeClass('applicationMenuItemActive');
			$('#tab04').removeClass('applicationMenuItemActive');
			$('#tab05').removeClass('applicationMenuItemActive');
			var addBookView = new AddBookView();
			window.App.table.show(addBookView);
		},

		showLibrary: function() {
			console.log("Controller: showLibrary called");
//			var list = new SampleCollection();
			var gridView = new GridView({ collection: window.App.collection });
			var footnoteView = new FootnoteView({collection: window.App.footnoteCollection}); 
			$('#tab01').removeClass('applicationMenuItemActive');
			$('#tab02').removeClass('applicationMenuItemActive');
			$('#tab03').addClass('applicationMenuItemActive');
			$('#tab04').removeClass('applicationMenuItemActive');
			$('#tab05').removeClass('applicationMenuItemActive');
			window.App.table.show(gridView);
			//window.App.footnote.show(footnoteView);
			//window.App.table.show(footnoteView);
		},

		showComplexView: function() {
			console.log("Controller: showComplexView called");
			var complexView = new ComplexView({ collection: window.App.collection });
			$('#tab01').removeClass('applicationMenuItemActive');
			$('#tab02').removeClass('applicationMenuItemActive');
			$('#tab03').removeClass('applicationMenuItemActive');
			$('#tab04').addClass('applicationMenuItemActive');
			$('#tab05').removeClass('applicationMenuItemActive');
			window.App.table.show(complexView);
		}
	});

	return AppController;
});
